<?php
/*
 * class.login.php
 * 文件说明:后台管理模块，登录
 * @version 0.1
 * @author samuel
 * @date 2009-05-06
 */
class admin_login {

	private $core = null;

	function  __construct(Core $core) {
		$this->core = $core;

		$this->run();
	}

	function run(){
        $errmsg = "";
		$chk = $_POST['chk'];
		if($chk === "on"){//检查登录
			$params['username'] = $_POST['username'];
			$params['password'] = $_POST['password'];
			$adminuser = $this->core->load('user::adminuser', $params);
			$chkres = $adminuser->validateLogin();
            switch($chkres){
                case 0:
                    $errmsg = "用户名密码错误！";
                    $this->core->tpl->assign('errmsg', $errmsg);
                    $this->core->tpl->display('login.html');
                    break;
                case -1:
                    $errmsg = "帐号被停用，请联系管理员！";
                    $this->core->tpl->assign('errmsg', $errmsg);
                    $this->core->tpl->display('login.html');
                    break;
                case 1:
                    $adminuser->updateLoginStatus();
                    header('Location: ./index.php?module=admin&act=showmain');
                    break;
            }
            return;
		}else{//返回登录界面
			$this->core->tpl->display('login.html');
			return;
		}
	}

}
?>
